<template>
    <div class="system-user-container">
        <QueryForm ref="queryForm" :dict="dict" :list="tableQuery" @refresh="initData" />
        <TableList ref="tableList" :dict="dict" :table="tableData" @click="handleClick" />
        <EditForm ref="form" :dict="dict" @refresh="initData" />
    </div>
</template>

<script>
    import QueryForm from '@/components/queryForm/index';
    import TableList from '@/components/tableList/index';
    import EditForm from '@/views/${moduleName}/${functionName}/form';
    import { remove } from '@/api/${moduleName}/${functionName}';
    import { getDictCodes } from '@/api/system/dictContent';

    export default {
        name: '${functionName?cap_first}Index',
        components: { QueryForm, TableList, EditForm },
        data() {
            return {
                dict: {},
                tableQuery: [
                    <#assign select=''>
        <#list table.columns as column>
            <#if (!column.sqlTypeName?contains("TEXT")) && (!column.columnName?contains("Id")) && column.columnName != "RemoveTag" && column.columnName != "Creator" && column.columnName != "CreateTime" && column.columnName != "Updater" && column.columnName != "UpdateTime">
                <#if column.sqlTypeName == "VARCHAR" && (column.remarks?contains("："))>
                    <#if select == ''>
                    <#assign select=column.columnNameFirstLower>
                    <#else>
                    <#assign select=(select + "," + column.columnNameFirstLower)>
                    </#if>
                    { label: '${column.remarks?substring(0,column.remarks?index_of("："))}', prop: '${column.columnNameFirstLower}', type: 'select', value: '', dict: '${column.columnNameFirstLower}' },
                <#elseif column.sqlTypeName == "VARCHAR" && (column.size?eval > 1) && (column.size?eval < 3000)  && (!column.remarks?contains("图片")) && (!column.remarks?contains("照片")) && (!column.remarks?contains("头像")) && (!column.remarks?contains("文件")) && (!column.remarks?contains("附件")) && (!column.remarks?contains("视频"))>
                    { label: '${column.remarks}', prop: '${column.columnNameFirstLower}', type: 'input', value: '' },
                </#if>
            </#if>
        </#list>
                ],
                tableData: {
                    headerRow: true,
                    tableUrl: '/${moduleName}/${functionName}/findPage.do',
                    tableOptions: ['add', 'delete'],
                    tableOptionsAuth: ['${moduleName?replace('/', '_')}_${functionName}_add', '${moduleName?replace('/', '_')}_${functionName}_delete_batch'],
                    columnsData: [
                        { type: 'selection', fixed: 'left', align: 'center' },
                        { type: 'index', label: '序号' },
                <#list table.columns as column>
                    <#if (!column.sqlTypeName?contains("TEXT")) && column.columnName !="Id" && column.columnName != "RemoveTag" && column.columnName != "Creator" && column.columnName != "CreateTime" && column.columnName != "Updater" && column.columnName != "UpdateTime">
                        <#if column.sqlTypeName == "VARCHAR" && (column.remarks?contains("："))>
                        { label: '${column.remarks?substring(0,column.remarks?index_of("："))}', prop: '${column.columnNameFirstLower}', align: 'center', minWidth: 200, type: 'select', dict: '${column.columnNameFirstLower}'},
                        <#elseif (column.size?eval > 1) && (column.size?eval < 3000)>
                        { label: '${column.remarks}', prop: '${column.columnNameFirstLower}', align: 'center', minWidth: 200 },
                        </#if>
                    </#if>
                </#list>
                        {
                            label: '操作', type: 'option', fixed: 'right', align: 'center', width: 150, list: [
                                { name: '编辑', code: 'edit', auth: '${moduleName?replace('/', '_')}_${functionName}_edit' },
                                { name: '删除', code: 'delete', auth: '${moduleName?replace('/', '_')}_${functionName}_delete' }
                            ]
                        }
                    ]
                }
            };
        },
        <#if select != ''>
        async created() {
            const res = await getDictCodes('${select}');
            this.dict = res.data;
        },
        </#if>
        mounted() {
            this.initData();
        },
        methods: {
            initData(data) {
                this.$refs.tableList.getList(data);
            },
            async handleClick(event, data) {
                if (event === 'add') {
                    this.$refs.form.show();
                } else if (event === 'edit') {
                    this.$refs.form.show(data);
                } else if (event === 'delete') {
                    const res = await remove({ id: data });
                    this.$baseMessageSuccess(res.msg);
                    this.initData();
                }
            }
        }
    };
</script>
